// src/pages/Home.js
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom'; // 用于导航到其他页面

function Home({ setUserData }) {
  const [height, setHeight] = useState('');
  const [weight, setWeight] = useState('');
  const [age, setAge] = useState('');
  const [dietPreference, setDietPreference] = useState('');

  const navigate = useNavigate();

  const handleSubmit = (e) => {
    e.preventDefault();
    // 保存用户数据
    setUserData({ height, weight, age, dietPreference });
    // 跳转到推荐菜谱页面
    navigate('/recommendations');
  };

  return (
    <div className="App">
      <h1>健康饮食建议平台</h1>
      <form onSubmit={handleSubmit}>
        <div>
          <label>身高（cm）：</label>
          <input
            type="number"
            value={height}
            onChange={(e) => setHeight(e.target.value)}
          />
        </div>
        <div>
          <label>体重（kg）：</label>
          <input
            type="number"
            value={weight}
            onChange={(e) => setWeight(e.target.value)}
          />
        </div>
        <div>
          <label>年龄：</label>
          <input
            type="number"
            value={age}
            onChange={(e) => setAge(e.target.value)}
          />
        </div>
        <div>
          <label>饮食偏好：</label>
          <select
            value={dietPreference}
            onChange={(e) => setDietPreference(e.target.value)}
          >
            <option value="vegan">纯素</option>
            <option value="vegetarian">素食</option>
            <option value="non-vegetarian">非素食</option>
          </select>
        </div>
        <button type="submit">提交</button>
      </form>
    </div>
  );
}

export default Home;